﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Spring.Context;
using Spring.Context.Support;

using Molic.Core.Controls.interfaces;
using System.Windows.Input;
using Common.Logging;

namespace Molic.Core.ActionHandlers
{
    /// <summary>
    /// This action handler is registered to save all of the objects on 
    /// the canvas to an XML file.
    /// </summary>
    class MolicSaveActionHandler : IMolicActionHandler
    {
        #region LOGGER

        private ILog _logger;
        /// <summary>
        /// Logger.
        /// </summary>
        private ILog Logger
        {
            get
            {
                if (_logger == null)
                {
                    _logger = LogManager.GetLogger(this.GetType());
                }
                return _logger;
            }
        }

        #endregion

        private IMolicController controller;
        /// <summary>
        /// The system controller.
        /// </summary>
        private IMolicController Controller
        {
            get
            {
                if (controller == null)
                {
                    IApplicationContext ctx = ContextRegistry.GetContext();
                    controller = (IMolicController)ctx.GetObject("MolicController");
                }
                return controller;
            }
        }

        #region IMolicActionHandler Members

        public ICommand Command
        {
            get { return ApplicationCommands.Save; }
        }

        public void OnQueryEnabled(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e)
        {
            //e.CanExecute = true;
        }
        public void OnExecute(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
        {
            if (Controller.Models == null)
                Logger.Debug("Saving..");
            else
                // do nothing here dude..
                Logger.Debug("Saving..");
        }

        #endregion
    }
}
